import os, sys, tempfile, copy, re
from subprocess import *

class parameter:
    def __init__(self, name, lower_limit = None, upper_limit = None, description = "", type = 1, value = None):
        self.name = name
        self.description = description
        self.type = type
        self.lower_limit = lower_limit
        self.upper_limit = upper_limit
        self.value = None

    def check(self):
        if self.type is 1:
            if self.lower_limit is None and self.upper_limit is not None and self.value <= self.upper_limit:
                return True
            elif self.upper_limit is None and self.lower_limit is not None and self.value >= self.lower_limit:
                return True
            elif self.value >= self.lower_limit and self.value <= self.upper_limit:
                return True
            elif self.lower_limit is None and self.upper_limit is None:
                return True

        """Raise exception if we have not returned True already.
        """
        if self.value:
            raise ValueError("Bad parameter value: %s (%s)" % (self.name, self.value))

        elif self.value:
            raise ValueError("Missing parameter value: %s" % (self.name))
